//////////////////////////////////////////////////////////////////////////
//
// GAM203
// Particle Emitter
// Emitter.h
// 
// Grant Johnson
// Qantm College
// 27/10/2010
//
//////////////////////////////////////////////////////////////////////////

#ifndef EMITTER_H
#define EMITTER_H

#include <list>
#include <d3dx9.h>

//Forward declarations
struct IDirect3DDevice9;
struct IDirect3DVertexBuffer9;
struct IDirect3DIndexBuffer9;

class RenderParams;

struct Particle
{
	D3DXVECTOR3 pos;
	D3DXVECTOR3 vel;
	D3DCOLOR col;
	float lifeRemaining;
};

class Emitter
{
public:
	//Struct used to define the type of vertices
	struct VertexData
	{
		//Vertices have a position and a colour
		D3DVECTOR pos;
		D3DCOLOR col;
	};

	//Define Flexible Vertex Format as a static const that is capable of a 3d position and a colour
	static const DWORD VERTEX_FORMAT_FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;

	Emitter();
	~Emitter();

	//Functionality
	virtual bool Setup(D3DXVECTOR3 a_pos) = 0;
	virtual void Update(float a_dt) = 0;
	virtual void Respawn(Particle& a_particle) = 0;
	virtual void Emit(Particle& a_particle) = 0;
	virtual void Render(float a_dt, IDirect3DDevice9 *a_pDevice, const RenderParams& a_renderParams) = 0;
 
protected:
	//Store vertex and index data
	IDirect3DVertexBuffer9* m_pVertexBuffer;

	//Store vertex and index data
	VertexData* m_pVertData;

	Particle* m_pParticles;

	//Spawn position
	D3DXVECTOR3 m_pos;

	//Particle initial velocity
	D3DXVECTOR3 m_velRange;

	//How many particles to emit per second
	float m_emitRate;

	//starting paramaters
	float m_life;

	bool m_useGravity;
	float m_gravity;

	int m_maxNumParticles;

	D3DXCOLOR m_colourStart;
	D3DXCOLOR m_colourEnd;
	float m_scaleStart;
	float m_scaleEnd;
	float m_rotation;

	float m_scale;

	//Direct3D texture pointer
	IDirect3DTexture9* m_pTex;

	D3DXMATRIX m_worldMatrix;
};

#endif //EMITTER_H